package main.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import main.dao.BaseDAO;
import main.dao.IBaseDAO;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("baseService")
@Transactional(propagation=Propagation.REQUIRED)
public class BaseService<T> implements IBaseService<T> {
	
//	@Resource
	@Resource(name="baseDAO")
	private IBaseDAO<T> baseDAO;
//    private BaseDAO<T> baseDAO = new BaseDAO<T>();
    
	@Override
	public T getByID(Class<T>entityClass, Serializable ID) {
		return baseDAO.getByID(entityClass, ID);
	}

	@Override
	public List<T> loadAll(Class<T> t) {
		return baseDAO.loadAll(t);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public Integer save(T entity) {
		return baseDAO.save(entity);
	}

	@Override
	public Boolean update(T entity) {		
		return baseDAO.update(entity);
	}

	@Override
	public Boolean remove(T entity) {
		return baseDAO.remove(entity);
	}

	public IBaseDAO<T> getBaseDAO() {
		return baseDAO;
	}
	
}
